import 'package:amoy_ticket/home/home_main_page.dart';
import 'package:amoy_ticket/movie/movie_main_page.dart';
import 'package:amoy_ticket/people/people_main/people_main_page.dart';
import 'package:amoy_ticket/perform/perform_main_page.dart';
import 'package:amoy_ticket/vip/vip_main_page.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import 'utils/router/log_util.dart';

class Tabs extends StatefulWidget {
  Tabs({Key? key}) : super(key: key);

  @override
  _TabsState createState() => _TabsState();
}

class _TabsState extends State<Tabs> {
  int _currentIndex = 0;
  var _pageList = [
    HomeMainPage(),
    MovieMainPage(),
    VipMainPage(),
    PerformMainPage(),
    PeopleMainPage(),
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: _pageList[_currentIndex],
      bottomNavigationBar: BottomNavigationBar(
        fixedColor: Color(0xFFff4881),
        currentIndex: _currentIndex,
        onTap: (int index) {
          if (mounted) {
            setState(() {
              if (this._currentIndex != index) {
                this._currentIndex = index;
                LogUtil.get().i(
                    '当前tabIndex~~$index 当前页面~~${_pageList[index].toString()}');
              }
            });
          }
        },
        type: BottomNavigationBarType.fixed,
        items: [
          _bottomNavigationBarItemWidget(
            'assets/images/home_icon.png',
            'assets/images/home_active_icon.png',
            '首页',
          ),
          _bottomNavigationBarItemWidget(
            'assets/images/movie_icon.png',
            'assets/images/movie_active_icon.png',
            '电影',
          ),
          _bottomNavigationBarItemWidget('assets/images/vip_icon.png',
              'assets/images/vip_active_icon.png', '会员'),
          _bottomNavigationBarItemWidget(
            'assets/images/movie_icon.png',
            'assets/images/movie_active_icon.png',
            '演出',
          ),
          _bottomNavigationBarItemWidget(
            'assets/images/people_icon.png',
            'assets/images/people_active_icon.png',
            '我的',
          ),
        ],
      ),
    );
  }

  BottomNavigationBarItem _bottomNavigationBarItemWidget(
      String imageUrl, String activeImageUrl, String label) {
    return BottomNavigationBarItem(
      icon: Image.asset(
        imageUrl,
        width: 21.w,
        height: 21.w,
      ),
      activeIcon: Image.asset(
        activeImageUrl,
        width: 23.w,
        height: 23.w,
        color: Color(0xFFff4881),
      ),
      label: label,
    );
  }
}
